﻿@{
    ViewBag.Title = "Land_List";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@section HeaderContent{
<script type="text/javascript">

    $(document).ready(function () {
        var page = $("#countPage").val();
        var url = "/CusLand/AD_GetCusLand";
        loadMore(url, page, 100);
    });


    function openNew() {
        var dt = new Date();
        var href = "/CusLand/AD_openEdit?id=&dt=" + dt.getTime();
        window.location.assign(href);

        //$("#wrapperDiv").load(href);
        //            $("#popup_content").load(href);
        //            showPopup('Insert product...');
    }


    function openEdit() {
        var lstSelected = "";
        $("td.classFist div.checked").each(function () {
            //$(this).attr('name');
            lstSelected = lstSelected + ";" + $(this).attr("id");
        });

        var lsCount = lstSelected.length;

        if (lsCount > 37) {
            cusAlert("Bạn chỉ cập nhật thông tin 1 căn hộ...");
        }
        else if (lsCount <= 0) {
            cusAlert("Vui lòng chọn 1 căn hộ để cập nhật");
        }
        else {
            var _DisCode = lstSelected.split(";");
            itemcode = _DisCode[1];
            var dt = new Date();

            window.location.assign("/CusLand/AD_openEdit?id=" + itemcode + "&dt=" + dt.getTime());
            //var href = "/CusLand/AD_openEdit?id=" + itemcode + "&dt=" + dt.getTime();
            //$("#wrapperDiv").load(href);

            //                $("#popup_content").load(href);
            //                showPopup('Insert product...');
        }

    }

    function openDelete() {       
        var lstSelected = "";
        $("td.classFist div.checked").each(function () {
            //$(this).attr('name');
            lstSelected = lstSelected + ";" + $(this).attr("id");
        });
        var lsCount = lstSelected.length;
        if (lsCount <= 0) {
            cusAlert("Vui lòng chọn 1 căn hộ để cập nhật");
        }
        else {
            if (confirm("Bạn muốn xoá các dữ liệu đã chọn")) {
                $.ajax({ type: 'POST', url: '/CusLand/AD_LandDelete', data: { Ids: lstSelected }, success: function (response) {

                    switch (response) {
                        case "01": // save fail                                          
                            cusAlert("Xoá thành công");
                            window.location.assign("/CusLand/AD_CusLandList");
                            break;

                        case "00": // ko the tao user, save sm_user_store loi                                           
                            cusAlert("Xoá không thành công... ");
                            break;

                        default:
                            break;
                    }
                }
                });
            }
        }
        
       // window.location.assign("/CusLand/AD_LandDelete?Ids=" + lstSelected + "&dt=" + dt.getTime());
    

    }

</script>
}
@section Toolbar {
    <a class="btn_boder btn_new" onclick="openNew()">New</a> <a class="btn_boder btn_edit"
        onclick="openEdit()">Edit</a> <a class="btn_boder btn_delete" onclick="openDelete()">Delete</a>
}
@Html.Hidden("countPage", 1)
<div id="mainDiv">
    <div id="wrapperDiv">
        <table id="tbList" cellpadding="0" cellspacing="0" class="tb_product">
            <tr>
                <th class="classFist" style="width: 20px"></th>
                <th>@Cus_LandModel.FieldName.Code.Translate()
                </th>
                <th>Tiêu đề</th>
                <th>@Cus_LandModel.FieldName.TotalCost.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.BDSLandName.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.BDSTypeName.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.NumRestRoom.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.NumFloor.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.Area.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.ProvinceName.Translate()
                </th>
                <th>@Cus_LandModel.FieldName.DictrictName.Translate()
                </th>

            </tr>
            @model Cus_LandModel
            @{
                List<Cus_LandModel> lstLand = ViewBag.lstLand != null ? (List<Cus_LandModel>)ViewBag.lstLand : new List<Cus_LandModel>();
            }
            @{
                foreach (var item in lstLand)
                {
                <tr>
                    <td class="classFist">
                        <div class="checkbox" onclick="SetChecked($(this));"  id="@item.Id">
                            @Html.Hidden("oder", item.Code)
                        </div>
                    </td>
                    <td>@item.Code
                    </td>
                    <td align="left">@item.Title</td>
                    <td>@item.TotalCost
                    </td>
                    <td>@item.BDSLandName
                    </td>
                    <td>@item.BDSTypeName
                    </td>
                    <td>@item.NumRestRoom
                    </td>
                    <td>@item.NumFloor
                    </td>
                    <td>@item.Area
                    </td>
                    <td>@item.ProvinceName
                    </td>
                    <td>@item.DictrictName
                    </td>

                </tr>
                }
            }
        </table>
    </div>
</div>
